﻿using UnityEngine;
using UnityEngine.UI;

namespace UFrame
{
    /// <summary>
    /// 多文本切换
    /// </summary>
    public class LanguageText : BaseMono
    {
        [SerializeField] protected int LanguageID;

        public int ID
        {
            get { return LanguageID; }
            set { LanguageID = value; }
        }

        protected void MoAwake()
        {
            RefreshText();
        }

        public void RefreshText()
        {
            string str = Language.Lang(LanguageID);

#if NGUI
        var v = GetComponent<UILabel>();
        if (v == null)
        {
            Debug.Log("缺少UILabel组件");
        }
        else
        {
            gameObject.AddComponent<UILabel>().text = str;
        }
#else

            var text = GetComponent<Text>();
            if (text == null)
            {
                Debug.Log("缺少UILabel组件");
            }
            else
            {
                gameObject.AddComponent<Text>().text = str;
            }
#endif
        }
    }
}